<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class BAAnalyseCooker extends BAEventCooker {

    public function getRecentBillList() {
        $todayBegin = strtotime(date('Y-m-d', time()) . ' 00:00:00');
        $todayEnd = $todayBegin + 60 * 60 * 24;
        //初始化10天数据
        $theseDayBill = array();
        for ($i = 9; $i >= 0; $i--) {
            $theseDayBill[$i] = 0;
        }
        //获取交易的数据
        $BAWeBillCooker = new BAWeBillCooker();
        $billType = $BAWeBillCooker->getCurrentBillType();
        //$billTypeId = $billType->getId();
        $billView = $BAWeBillCooker->getBillList($billType);
        //1、通过$billTime提取最近10天交易数据，并赋值给$theseDayBill
        //2、赋值给图表
        $billTime = '';
        $payAmount = '';
        foreach ($billView as $billList) {
            if ($billList instanceof BTreeList) {
                if ($billList->getItem('billTime') != NULL) {
                    $billTime = $billList->getItem('billTime')->value;
                }
                if ($billList->getItem('payAmount') != NULL) {
                    $payAmount = $billList->getItem('payAmount')->value;
                }
                switch ($billTime) {
                    case ($billTime >= $todayBegin && $billTime <= $todayEnd):
                        $theseDayBill[0] += $payAmount;
                        break;
                    case ($billTime >= $todayBegin - 60 * 60 * 24 * 1 && $billTime <= $todayEnd - 60 * 60 * 24 * 1):
                        $theseDayBill[1] += $payAmount;
                        break;
                    case ($billTime >= $todayBegin - 60 * 60 * 24 * 2 && $billTime <= $todayEnd - 60 * 60 * 24 * 2):
                        $theseDayBill[2] += $payAmount;
                        break;
                    case ($billTime >= $todayBegin - 60 * 60 * 24 * 3 && $billTime <= $todayEnd - 60 * 60 * 24 * 3):
                        $theseDayBill[3] += $payAmount;
                        break;
                    case ($billTime >= $todayBegin - 60 * 60 * 24 * 4 && $billTime <= $todayEnd - 60 * 60 * 24 * 4):
                        $theseDayBill[4] += $payAmount;
                        break;
                    case ($billTime >= $todayBegin - 60 * 60 * 24 * 5 && $billTime <= $todayEnd - 60 * 60 * 24 * 5):
                        $theseDayBill[5] += $payAmount;
                        break;
                    case ($billTime >= $todayBegin - 60 * 60 * 24 * 6 && $billTime <= $todayEnd - 60 * 60 * 24 * 6):
                        $theseDayBill[6] += $payAmount;
                        break;
                    case ($billTime >= $todayBegin - 60 * 60 * 24 * 7 && $billTime <= $todayEnd - 60 * 60 * 24 * 7):
                        $theseDayBill[7] += $payAmount;
                        break;
                    case ($billTime >= $todayBegin - 60 * 60 * 24 * 8 && $billTime <= $todayEnd - 60 * 60 * 24 * 8):
                        $theseDayBill[8] += $payAmount;
                        break;
                    case ($billTime >= $todayBegin - 60 * 60 * 24 * 9 && $billTime <= $todayEnd - 60 * 60 * 24 * 9):
                        $theseDayBill[9] += $payAmount;
                        break;
                    default :
                        break;
                }
            }
        }
        return $theseDayBill;
    }

}
